package com.j2009.springbootproject.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * ClassName: LoginInterceptor
 * Description:
 * date: 2021/3/25 15:16
 *
 * @author wuyafeng
 * @version 1.0   softeem.com
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException {

         //判断是否登录 ，如果没有登录  就跳转登录页面
        if(request.getSession().getAttribute("user")!=null){
            return true;
        }else {
            //转发
            request.getRequestDispatcher("/adminUser/toLogin").forward(request,response);

            return false;
        }
    }
}
